GDIR=../../../..
GIMDIR=$(GDIR)
LNMDIR=$(GDIR)/LnMlib/src
KMLDIR=kml
GIMIPATH=$(GDIR)/GIMI
MACIPATH=$(GDIR)/MaCI

CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS)
CPPFLAGS=-Wall $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS)
DEBUG=-O2 -g3
CMISCFLAGS=
CPPMISCFLAGS=-DGIMI_CLIENT_API=10303
DEFINITIONS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES
EXCEPTIONS=-fexceptions -ffast-math 
CINCLUDES=-I. -I../../scanmatch -I../../mcl -I$(GDIR)/utils
CPPINCLUDES=-I. -I../../scanmatch -I../../mcl $(OCCU_INCLUDE) -I$(GDIR)/glutImageGUI -I$(GDIR)/utils \
						-I$(GIMDIR)/ImageUtils/JPEGEncoder \
						`xml2-config --cflags` \
						-I$(GIMBOPATH)/components/MaCI_Player/players \
						$(MACI_INCLUDE_PATHS) \
						$(INCGIMI) -I$(KMLDIR) $(LNM_UTIL_INCLUDE) -I$(GIMDIR)/glutgui

LD=g++
LDFLAGS=
LIBS=-lrt -lpthread -lGL -lGLU -lglut -ljpeg `xml2-config --libs`


SRCSC=
#SRCSCPP=j2b2.cpp $(OCCU_SRC_CPP)
VPATH=
CPPGIMI=
CGIMI=

include Makefile.mcl
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile
include $(GIMIPATH)/Makefile.gimi
include $(LNMDIR)/map/Makefile.occu 
include $(LNMDIR)/BetB_dt/Makefile.bbdt
include $(LNMDIR)/utils/Makefile.util

CSRCUTIL=$(GIMDIR)/utils/ownutils.c $(GIMDIR)/utils/owndebug.c

CPPIMAGEGUI=$(GIMDIR)/glutImageGUI/glutImageGUI.cpp \
	$(GIMDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.cpp \
	$(GIMDIR)/glutgui/RGBImage.cpp

#SRCSC += $(CSRCUTIL)
SRCSCPP=$(OCCU_SRC_CPP) $(CPPMCL) $(CPPSM) $(BBDT_SRC_CPP) $(BBDT_DIR)/bbPlotUtil.cpp
KMLSRC=$(KMLDIR)/KCtree.cpp $(KMLDIR)/KMcenters.cpp $(KMLDIR)/KMfilterCenters.cpp $(KMLDIR)/KMlocal.cpp \
	$(KMLDIR)/KMterm.cpp $(KMLDIR)/KCutil.cpp $(KMLDIR)/KMdata.cpp $(KMLDIR)/KM_ANN.cpp $(KMLDIR)/KMeans.cpp \
	$(KMLDIR)/KMrand.cpp


## Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o) $(CGIMI:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp) \
	$(CPPIMAGEGUI:.cpp=.opp) \
	$(CPPGIMI:.cpp=.opp) \
	$(MACI_BASE_SRC_CPP:.cpp=.opp) \
	$(MACI_EXT_SRC_CPP:.cpp=.opp) \
	$(MACI_INTERFACE_RANGING_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_RANGINGSERVER_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_POSITION_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_POSITIONSERVER_CPP:.cpp=.opp)\
	$(KMLSRC:.cpp=.opp) $(UTIL_SRC_CPP:.cpp=.opp) \
	$(MACIPATH)/utils/InterfaceFileLoggersAndReaders/PositionFileWriter.opp \
	$(MACIPATH)/utils/InterfaceFileLoggersAndReaders/PositionFileReader.opp \
	$(MACIPATH)/utils/InterfaceFileLoggersAndReaders/RangingFileReader.opp \
	$(MACIPATH)/utils/InterfaceFileLoggersAndReaders/RangingFileWriter.opp

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

TARGETS=rocla_convert create_map convert_maci_data scanmatch match2map global-localization-tester match2map2 match_posesets \
	match2map-no-mapping generate-journal-results

all: $(TARGETS)

	
rocla_convert: $(OBJSC) $(OBJSCPP) rocla_convert.opp
			@$(LINK) -o $@ $^ $(LIBS)
			@echo "      [LD] $@"

create_map: $(OBJSC) $(OBJSCPP) create_map.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"

convert_maci_data: $(OBJSC) $(OBJSCPP) convert_maci_data.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"

scanmatch: $(OBJSC) $(OBJSCPP) scanmatch.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"	

match2map: $(OBJSC) $(OBJSCPP) match2map.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"	

match2map-no-mapping: $(OBJSC) $(OBJSCPP) match2map-no-mapping.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"	

match2map2: $(OBJSC) $(OBJSCPP) match2map2.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"	

match_posesets: $(OBJSC) $(OBJSCPP) match_posesets.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"	

global-localization-tester: $(OBJSC) $(OBJSCPP) global-localization-tester.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"	

generate-journal-results: $(OBJSC) $(OBJSCPP) generate-journal-results.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"	
	
clean:
	rm -f $(OBJSC) $(OBJSCPP) *.opp *.o $(TARGETS) \
 		*.out *~ *.d *.dpp

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<
